# parse_data 用于解析数据

def parse_page_data(page_data):
    """解析数据"""
    # 存储基础信息
    coords = []  # 坐标信息
    words = []  # 文本信息
    boxes = []  # 边框信息(x0,y0,width,height)

    # 解析文本快坐标和内容(保留原始顺序)
    for i, item in enumerate(page_data['page_word']):
        # 获取单字基础信息
        annotation_id = item.get('annotation_id', '')
        word = item.get('word', '')
        recognition_rate = item.get('recognition_rate', '')
        word_image_path = item.get('word_image_path', '')

        # 获取坐标信息
        box_str = item.get('word_coordinates')
        x0, y0, w, h = map(float, box_str.split(','))
        x_start, x_end = x0, x0 + w
        y_start, y_end = y0, y0 + h
        x_center, y_center = x0 + w / 2, y0 + h / 2
        coords.append({
            'annotation_id': annotation_id,
            'char_order':None,
            'word': word,
            'word_image_path': word_image_path,
            'recognition_rate': item['recognition_rate'],
            'word_coordinates': item['word_coordinates'],
            'pinyin': None,
            'translation_info': {
                'literal_translation': None,
                'translation_elem': []
            },
            'width': w,
            'height': h,
            'x_start': x_start,
            'x_end': x_end,
            'y_start': y_start,
            'y_end': y_end,
            'x_center': x_center,
            'y_center': y_center
        })

    return coords, words, boxes
